#!/bin/bash

# if mac os, then  sed -i  "" 's/old/new/g' file
sed -i "s/KAFKA_BROKER/${KAFKA_BROKER}/g" /usr/share/logstash/pipeline/logstash.conf
sed -i "s/KAFKA_GROUP_ID/${KAFKA_GROUP_ID}/g" /usr/share/logstash/pipeline/logstash.conf
sed -i "s/LOGSTASH_CLIENT/${LOGSTASH_CLIENT}/g" /usr/share/logstash/pipeline/logstash.conf
sed -i "s/KAFKA_AUTO_OFFSET_RESERT/${KAFKA_AUTO_OFFSET_RESERT}/g" /usr/share/logstash/pipeline/logstash.conf
sed -i "s/KAFKA_ENABLE_AUTO_COMMIT/${KAFKA_ENABLE_AUTO_COMMIT}/g" /usr/share/logstash/pipeline/logstash.conf
sed -i "s/KAFKA_TOPICS/${KAFKA_TOPICS}/g" /usr/share/logstash/pipeline/logstash.conf
sed -i "s/ES_HOST/${ES_HOST}/g" /usr/share/logstash/pipeline/logstash.conf
sed -i "s/ES_INDEX/${ES_INDEX}/g" /usr/share/logstash/pipeline/logstash.conf
sed -i "s/ES_USERNAME/${ES_USERNAME}/g" /usr/share/logstash/pipeline/logstash.conf
sed -i "s/ES_PASSWORD/${ES_PASSWORD}/g" /usr/share/logstash/pipeline/logstash.conf
sed -i "s/STDOUT/${STDOUT}/g" /usr/share/logstash/pipeline/logstash.conf

cd /usr/share/logstash 
cat ./pipeline/logstash.conf

nohup ./bin/logstash -f ./pipeline/logstash.conf > ./logstash.out &
tail -f logstash.out